package com.vic.queue_param.auto_delete;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.vic.utils.RabbitmqUtils;

import java.nio.charset.StandardCharsets;

/**
 * 发送者
 */
public class Producer {

    public static void main(String[] args) throws Exception {

        Connection conn = RabbitmqUtils.getConn();
        Channel channel = conn.createChannel();

        // 声明队列
        /**
         * 各参数的说明，请参考Technology/RabbitMQ/rabbitmq系列
         */
        // 当无消费者连接时（前提是有过消息的消费），自动删除队列
        channel.queueDeclare(Consts.QUEUE_NAME, false, false, true , null);

        for (int i = 1; i <= 2; i++) {
            channel.basicPublish("", Consts.QUEUE_NAME, null, ("好消息" + i).getBytes(StandardCharsets.UTF_8));
        }
        System.out.println("发送消息完成");

        channel.close();
        conn.close();

    }

}
